CLS
@ECHO OFF
ECHO. =======================================================
ECHO. SYMFONY COMMAND BATCH TOOL FOR PROPEL TYPE SUPPORT
ECHO. (c) 2010 nguyen nhu tuan - +84 01689050105
ECHO. junzecom@junzecom.com OR junzennt@gmail.com
ECHO. =======================================================

REM I'm using XAMPP 1.7.0 for this tut
REM The first you must add to Variable Environment PATH D:\xampp\apache\bin;D:\xampp\php;D:\xampp\mysql\bin;

REM   =======================================================
REM Set Variable for project
SET PARTITIONPROJECT=D:
SET PATHPROJECT=D:\xampp\pro_elearning\
SET SYMFONYPATH=D:\xampp\libs\symfony\
SET XAMPPPATH=D:\xampp\

SET NAMEPROJECT=trunk
SET PORTPROJECT=8181

SET DATABASEHOST=localhost
SET DATABASEDB=junzecom_elearning
SET DATABASEUSER=root
SET DATABASEPASS=

REM Value of CREATMODELFROM is "schema" or "db"
SET CREATMODELFROM=db
REM Value of LOADDEFAULTDATA is "yes" or "no"
SET LOADDEFAULTDATA=no
REM   =======================================================
ECHO.
ECHO SYMFONY CHECK WEBSERVER
php %SYMFONYPATH%data\bin\symfony
php %SYMFONYPATH%data\bin\check_configuration.php
ECHO. -------------------------------------------------------
ECHO.
ECHO 1) Start create Project
ECHO 2) Start create Blank Project
ECHO 3) Create anything for project
ECHO 4) Exit
SET /P CH=Enter start:
IF %CH%==1 GOTO StartCreateProject
IF %CH%==2 GOTO StartCreateBlankProject
IF %CH%==3 GOTO MENU
IF %CH%==4 GOTO END
GOTO END

:StartCreateBlankProject
SET FLAGBLANK=1
GOTO StartCreateProject
SET FLAGBLANK=0

:StartCreateProject
CLS
REM MAIN PROCCESS PROJECT
%PARTITION%
CD %PATHPROJECT%
REM 1) Creat project folder
MKDIR %NAMEPROJECT%

REM   -------------------------------------------------------
IF exist %NAMEPROJECT% GOTO Normal
IF not exist %NAMEPROJECT% GOTO Abort
REM   -------------------------------------------------------

:Abort
ECHO Sorry ... cannot create symfony project!
ECHO Email for me junzennt@gmail.com to receive support
pause
GOTO END

:Normal
REM Goto projetc folder
CD %NAMEPROJECT%

REM 2) Create Symfony project
php %SYMFONYPATH%data\bin\symfony generate:project %NAMEPROJECT%

REM 2.1) Create two application Frontend and Backend for project
php symfony generate:app --escaping-strategy=on --csrf-secret=Unique$ecret frontend
php symfony generate:app --escaping-strategy=on --csrf-secret=Unique$ecret backend

REM 3) Config database
php symfony configure:database "mysql:host=%DATABASEHOST%;dbname=%DATABASEDB%" %DATABASEUSER% %DATABASEPASS%

REM   -------------------------------------------------------
IF %FLAGBLANK%==1 GOTO ConfigXamppApache
IF %CREATMODELFROM%==schema GOTO FromSchema
IF %CREATMODELFROM%==db GOTO FromDB
GOTO MENU
REM   -------------------------------------------------------

:FromSchema
REM 4) Cteate schema for project in config/schema.yml
REM 4.1) If have schema, you can generator SQL from schema by command 
php %SYMFONYPATH%data\bin\symfony propel:build-sql
php symfony propel:insert-sql --no-confirmation
GOTO NextStep1
:FromDB
REM 4.2) If have database, you can generator schema from database by command
php %SYMFONYPATH%data\bin\symfony propel:build-schema
GOTO NextStep1

:NextStep1
REM 4.3) Create Model from schema
php %SYMFONYPATH%data\bin\symfony propel:build-model
REM 5) build-all contain all Step 4, beyond contain step create Form and Validation for Model
REM 5.1) build-all-load is build-all + data-load
REM Create Database default in folder. Example: data/fixtures/010_exam.yml. Note number order in header name.
REM php symfony propel:data-load
REM php symfony propel:build-all-load --no-confirmation
IF %LOADDEFAULTDATA%==no php symfony propel:build-all --no-confirmation
IF %LOADDEFAULTDATA%==yes php symfony propel:build-all-load --no-confirmation

REM Create Module with Model
REM php symfony propel:generate-module --with-show --non-verbose-templates frontend tenModule tenModel
REM Create Module without Model
REM php symfony generate:module frontend tenModule

REM Clear cache
REM php symfony cache:clear
REM php symfony cc

REM Install Plugin
REM php symfony plugin:install sfReCaptchaPlugin

REM   =======================================================
REM Add visual host for Xampp Apache config
REM Stop Xampp apache
:ConfigXamppApache
%XAMPPPATH%apache\bin\pv -f -k apache.exe -q
if not exist %XAMPPPATH%apache\logs\httpd.pid GOTO NextStep2
del %XAMPPPATH%apache\logs\httpd.pid
:NextStep2
ECHO #======================================================== >> %XAMPPPATH%apache\conf\httpd.conf
ECHO # NOTE: Remove double quotes character before and after tag >> %XAMPPPATH%apache\conf\httpd.conf
ECHO # Be sure to only have this line once in your configuration >> %XAMPPPATH%apache\conf\httpd.conf
ECHO NameVirtualHost 127.0.0.1:%PORTPROJECT% >> %XAMPPPATH%apache\conf\httpd.conf

ECHO # This is the configuration for %NAMEPROJECT% >> %XAMPPPATH%apache\conf\httpd.conf
ECHO Listen 127.0.0.1:%PORTPROJECT% >> %XAMPPPATH%apache\conf\httpd.conf

ECHO "<VirtualHost 127.0.0.1:%PORTPROJECT%>" >> %XAMPPPATH%apache\conf\httpd.conf
ECHO   ServerName %NAMEPROJECT%.localhost >> %XAMPPPATH%apache\conf\httpd.conf
ECHO   DocumentRoot "%PATHPROJECT%%NAMEPROJECT%\web" >> %XAMPPPATH%apache\conf\httpd.conf
ECHO   DirectoryIndex index.php >> %XAMPPPATH%apache\conf\httpd.conf
ECHO   "<Directory "%PATHPROJECT%%NAMEPROJECT%\web">" >> %XAMPPPATH%apache\conf\httpd.conf
ECHO 	AllowOverride All >> %XAMPPPATH%apache\conf\httpd.conf
ECHO 	Allow from All >> %XAMPPPATH%apache\conf\httpd.conf
ECHO   "</Directory>" >> %XAMPPPATH%apache\conf\httpd.conf

ECHO   Alias /sf "%SYMFONYPATH%data\web\sf" >> %XAMPPPATH%apache\conf\httpd.conf
ECHO   "<Directory "%SYMFONYPATH%data\web\sf">" >> %XAMPPPATH%apache\conf\httpd.conf
ECHO 	AllowOverride All >> %XAMPPPATH%apache\conf\httpd.conf
ECHO 	Allow from All >> %XAMPPPATH%apache\conf\httpd.conf
ECHO   "</Directory>" >> %XAMPPPATH%apache\conf\httpd.conf
ECHO "</VirtualHost>" >> %XAMPPPATH%apache\conf\httpd.conf
ECHO #======================================================== >> %XAMPPPATH%apache\conf\httpd.conf
START /max /wait NOTEPAD.EXE %XAMPPPATH%apache\conf\httpd.conf

GOTO MENU
REM Start Xampp apache
REM %XAMPPPATH%apache\bin\apache.exe
REM IF errorlevel 255 GOTO MENU
REM IF errorlevel 1 GOTO ApacheError
REM :ApacheError
REM :error
REM ECHO.
REM ECHO Apache konnte nicht gestartet werden
REM ECHO Apache could not be started
REM PAUSE
REM GOTO MENU
REM   =======================================================

REM CREAT my Menu
:MENU
CLS
%PARTITION%
CD %PATHPROJECT%
REM Goto projetc folder
CD %NAMEPROJECT%
ECHO.
ECHO. =======================================================
ECHO. SYMFONY COMMAND BATCH TOOL FOR PROPEL TYPE SUPPORT v1.0 beta
ECHO. (c) 2010 nguyen nhu tuan - +84 01689050105
ECHO. junzecom@junzecom.com OR junzennt@gmail.com
ECHO. Any support on www.dehieu.net
ECHO.     - You have been created symfony project: %NAMEPROJECT% sucssecfull !
ECHO.     - at %PATHPROJECT%%NAMEPROJECT% with two application as "frontend" and "backend"
ECHO.     - Remove double quotes character before and after tag, and restart Apache
ECHO.     - You can access yor site follow url http://localhost:%PORTPROJECT%/
ECHO. -------------------------------------------------------
ECHO. Now, do you want creat:
ECHO.     1 - Build all load
ECHO.       1.1 - Build all
ECHO.         1.1.0 - Build schema
ECHO.         1.1.1 - Build model
ECHO.         1.1.2 - Build sql
ECHO.         1.1.3 - Build form
ECHO.         1.1.4 - Build filters
ECHO.         1.1.5 - Insert sql
ECHO.       1.2 - Data load
ECHO.     2 - Application
ECHO.     3 - Module
ECHO.     4 - Plugin Install
ECHO.       4.0 - Plugin installed list
ECHO.       4.1 - Plugin Uninstall
ECHO. -------------------------------------------------------
ECHO.     6 - Admin generator
ECHO.       6.1 - plugin:publish-assets
ECHO.       6.2 - Setup sfGuardPlugin
ECHO.         6.2.1 - sfGuardPlugin Create account default
ECHO.         6.2.2 - sfGuardPlugin add super permission
ECHO. -------------------------------------------------------
ECHO.     ws1 - Add Alias folder
ECHO. -------------------------------------------------------
ECHO.     cc - Clear Cache
ECHO.     tt - Test Module
ECHO.     00 - View Browse
ECHO.     0 - Exit
ECHO. =======================================================
ECHO.
SET /P M=What do you want ?:
REM   -------------------------------------------------------
IF %M%==1 GOTO ProBAL
IF %M%==1.1 GOTO ProBAL11
IF %M%==1.1.0 GOTO ProBAL110
IF %M%==1.1.1 GOTO ProBAL111
IF %M%==1.1.2 GOTO ProBAL112
IF %M%==1.1.3 GOTO ProBAL113
IF %M%==1.1.4 GOTO ProBAL114
IF %M%==1.1.5 GOTO ProBAL115
IF %M%==1.2 GOTO ProBAL12
IF %M%==2 GOTO ProAPP
IF %M%==3 GOTO ProMOD
IF %M%==4 GOTO ProPLU
IF %M%==4.0 GOTO ProPLU_0
IF %M%==4.1 GOTO ProPLU_1
IF %M%==6 GOTO ProADG
IF %M%==6.1 GOTO ProPPA
IF %M%==6.2 GOTO ProPSFG
IF %M%==6.2.1 GOTO ProPSFG1
IF %M%==6.2.2 GOTO ProPSFG2
IF %M%==cc GOTO ProCC
IF %M%==tt GOTO ProTESTMOD
IF %M%==00 GOTO ProVW
IF %M%==ws1 GOTO ProALIASADD
IF %M%==0 GOTO END
GOTO MENU
REM   -------------------------------------------------------

:ProTESTMOD
ECHO.
SET /P MODULECREATNAME=Module name:
SET /P MODULECREATAPP=For application:
php %SYMFONYPATH%data\bin\symfony test-functional %MODULECREATAPP% %MODULECREATNAME%
ECHO.
ECHO Test Module %MODULECREATNAME% for %MODULECREATAPP% successful !.
PAUSE
GOTO MENU

:ProPSFG1
SET /P PROPSFG1ACOUNT=Username:
SET /P PROPSFG1PASS=Password:
php symfony guard:create-user %PROPSFG1ACOUNT% %PROPSFG1PASS%
ECHO.
ECHO Create account successful !.
PAUSE
GOTO MENU

:ProPSFG2
SET /P PROPSFG2ACOUNT=For Username:
php symfony guard:promote %PROPSFG2ACOUNT%
ECHO.
ECHO Add super permission for %PROPSFG2ACOUNT% successful !.
PAUSE
GOTO MENU

:ProPSFG
CLS
ECHO.
ECHO Connect to Internet before setup Plugin !.
PAUSE
php symfony plugin:install sfGuardPlugin
php symfony propel:build-all-load --no-confirmation
IF exist config_text.txt DEL config_text.txt
copy NUL config_text.txt
ECHO #For apps\backend or frontend\config\settings.yml >> config_text.txt
ECHO all: >> config_text.txt
ECHO   .settings: >> config_text.txt
ECHO #For backend >> config_text.txt
ECHO     enabled_modules:      [default, sfGuardGroup, sfGuardUser, sfGuardPermission, sfGuardAuth] >> config_text.txt
ECHO #For frontend >> config_text.txt
ECHO     enabled_modules:      [default, sfGuardAuth] >> config_text.txt
ECHO. >> config_text.txt
ECHO   .actions: >> config_text.txt
ECHO     login_module:           sfGuardAuth >> config_text.txt
ECHO     login_action:           signin >> config_text.txt
ECHO. >> config_text.txt
ECHO     secure_module:          sfGuardAuth >> config_text.txt
ECHO     secure_action:          secure >> config_text.txt
ECHO. >> config_text.txt

ECHO #For apps\backend or frontend\config\routing.yml >> config_text.txt
ECHO sf_guard_signin: >> config_text.txt
ECHO   url:   /login >> config_text.txt
ECHO   param: { module: sfGuardAuth, action: signin } >> config_text.txt
ECHO. >> config_text.txt
ECHO sf_guard_signout: >> config_text.txt
ECHO   url:   /logout >> config_text.txt
ECHO   param: { module: sfGuardAuth, action: signout } >> config_text.txt
ECHO. >> config_text.txt 
ECHO sf_guard_password: >> config_text.txt
ECHO   url:   /request_password >> config_text.txt
ECHO   param: { module: sfGuardAuth, action: password } >> config_text.txt
ECHO. >> config_text.txt

ECHO #For apps\backend or frontend\config\security.yml >> config_text.txt
ECHO default: >> config_text.txt
ECHO   is_secure: on >> config_text.txt
ECHO. >> config_text.txt

ECHO #For apps\backend or frontend\config\app.yml >> config_text.txt
ECHO all: >> config_text.txt
ECHO   sf_guard_plugin: >> config_text.txt
ECHO     routes_register: false >> config_text.txt
ECHO. >> config_text.txt

ECHO #For apps\backend or frontend\config\filters.yml >> config_text.txt
REM ECHO remember_me: >> config_text.txt
REM ECHO   class: sfGuardRememberMeFilter >> config_text.txt
ECHO security: >> config_text.txt
ECHO   class: sfGuardBasicSecurityFilter >> config_text.txt
ECHO. >> config_text.txt
ECHO. >> config_text.txt

ECHO #Change apps\backend or frontend\lib\myUser.class.php >> config_text.txt
ECHO class myUser extends sfGuardSecurityUser >> config_text.txt
ECHO { >> config_text.txt
ECHO } >> config_text.txt
ECHO. >> config_text.txt

ECHO.
ECHO Setup sfGuardPlugin successful !.
ECHO. See all config for plugin in config_text.txt at %PATHPROJECT%%NAMEPROJECT%
ECHO. Using 6.2.1 and 6.2.2 create and add permission for account
PAUSE
GOTO MENU

:ProBAL
php symfony propel:build-all-load --no-confirmation
ECHO.
ECHO Build all load successful !.
PAUSE
GOTO MENU

:ProBAL11
php symfony propel:build-all --no-confirmation
ECHO.
ECHO Build all successful !.
PAUSE
GOTO MENU

:ProBAL110
php symfony propel:build-schema
ECHO.
ECHO Build Schema successful !.
PAUSE
GOTO MENU

:ProBAL111
php symfony propel:build-model
ECHO.
ECHO Build Model successful !.
PAUSE
GOTO MENU

:ProBAL112
php symfony propel:build-sql
ECHO.
ECHO Build SQL successful !.
PAUSE
GOTO MENU

:ProBAL113
php symfony propel:build-forms
ECHO.
ECHO Build Form successful !.
PAUSE
GOTO MENU

:ProBAL114
php symfony propel:build-filters
ECHO.
ECHO Build Filters successful !.
PAUSE
GOTO MENU

:ProBAL115
php symfony propel:insert-sql --no-confirmation
ECHO.
ECHO Insert SQL successful !.
PAUSE
GOTO MENU

:ProBAL12
php symfony propel:data-load --no-confirmation
ECHO.
ECHO Data load successful !.
PAUSE
GOTO MENU

:ProADG
ECHO.
ECHO. -------------------------------------------------------
ECHO. LIST MODEL FOR CREATE
php -f d:\xampp\pro_elearning\trunk\listtables.php -- %DATABASEDB%
ECHO. -------------------------------------------------------
SET /P MODULECREATNAME=Module name:
SET /P MODULECREATAPP=For application:
SET /P MODULECREATMOL=By Model:
php %SYMFONYPATH%data\bin\symfony propel:generate-admin %MODULECREATAPP% %MODULECREATMOL% --module=%MODULECREATNAME%
REM IF exist vidu.txt DEL vidu.txt
REM copy NUL vidu.txt
REM ECHO # apps/backend/config/routing.yml >> %PATHPROJECT%%NAMEPROJECT%\apps\%MODULECREATAPP%\config\routing.yml
REM ECHO. >> %PATHPROJECT%%NAMEPROJECT%\apps\%MODULECREATAPP%\config\routing.yml
REM ECHO # For Module %MODULECREATNAME% >> %PATHPROJECT%%NAMEPROJECT%\apps\%MODULECREATAPP%\config\routing.yml
REM ECHO %MODULECREATNAME%: >> %PATHPROJECT%%NAMEPROJECT%\apps\%MODULECREATAPP%\config\routing.yml
REM ECHO   class: sfPropelRouteCollection >> %PATHPROJECT%%NAMEPROJECT%\apps\%MODULECREATAPP%\config\routing.yml
REM ECHO   options: >> %PATHPROJECT%%NAMEPROJECT%\apps\%MODULECREATAPP%\config\routing.yml
REM ECHO     model:                %MODULECREATMOL% >> %PATHPROJECT%%NAMEPROJECT%\apps\%MODULECREATAPP%\config\routing.yml
REM ECHO     module:               %MODULECREATNAME% >> %PATHPROJECT%%NAMEPROJECT%\apps\%MODULECREATAPP%\config\routing.yml
REM ECHO     with_wildcard_routes: true >> %PATHPROJECT%%NAMEPROJECT%\apps\%MODULECREATAPP%\config\routing.yml
REM ECHO.
REM ECHO Open file routing_example.txt copy all text to apps/backend/config/routing.yml
ECHO Open file apps/%MODULECREATAPP%/config/routing.yml and check bottom file
ECHO You can access follow url http://localhost/backend.php/%MODULECREATNAME%
ECHO Creat Module %MODULECREATNAME% for %MODULECREATAPP% successful !.
PAUSE
GOTO MENU

REM Create Application Part
:ProAPP
SET /P APPNAME=Application name:
php %SYMFONYPATH%data\bin\symfony generate:app --escaping-strategy=on --csrf-secret=Unique$ecret %APPNAME%
ECHO.
ECHO Create application %APPNAME% successful !.
PAUSE
GOTO MENU

REM Create Module Part
:ProMOD
SET /P MODULECREATTYPE=Module with Model - 1(without Model - 2):
IF %MODULECREATTYPE%==1 GOTO ModuleType1
IF %MODULECREATTYPE%==2 GOTO ModuleType2
GOTO MENU
:ModuleType1
ECHO.
ECHO. -------------------------------------------------------
ECHO. LIST MODEL FOR CREATE
php -f d:\xampp\pro_elearning\trunk\listtables.php -- %DATABASEDB%
ECHO. -------------------------------------------------------
SET /P MODULECREATNAME=Module name:
SET /P MODULECREATAPP=For application:
SET /P MODULECREATMOL=By Model:
php %SYMFONYPATH%data\bin\symfony propel:generate-module --with-show --non-verbose-templates %MODULECREATAPP% %MODULECREATNAME% %MODULECREATMOL%
ECHO.
ECHO Creat Module %MODULECREATNAME% for %MODULECREATAPP% successful !.
PAUSE
GOTO MENU
:ModuleType2
SET /P MODULECREATNAME=Module name:
SET /P MODULECREATAPP=For application:
php %SYMFONYPATH%data\bin\symfony generate:module %MODULECREATAPP% %MODULECREATNAME%
ECHO.
ECHO Creat Module %MODULECREATNAME% for %MODULECREATAPP% successful !.
PAUSE
GOTO MENU

REM Create Plugin Part
:ProPLU
SET /P PLUGINNAME=Plugin name:
php %SYMFONYPATH%data\bin\symfony plugin:install %PLUGINNAME%
ECHO.
ECHO Setup Plugin %PLUGINNAME% successful !.
PAUSE
GOTO MENU

:ProPLU_0
php %SYMFONYPATH%data\bin\symfony plugin:list
ECHO.
PAUSE
GOTO MENU

:ProPLU_1
php %SYMFONYPATH%data\bin\symfony plugin:list
ECHO.
SET /P PLUGINNAME=Plugin name:
php %SYMFONYPATH%data\bin\symfony plugin:uninstall %PLUGINNAME%
ECHO.
ECHO Uninstall Plugin %PLUGINNAME% successful !.
PAUSE
GOTO MENU

REM Clear cache
:ProCC
php %SYMFONYPATH%data\bin\symfony cache:clear
ECHO.
ECHO Clear Cache successful !.
PAUSE
GOTO MENU

REM Install the assets in your project
:ProPPA
REM php %SYMFONYPATH%data\bin\symfony plugin:install sfProtoculousPlugin
php %SYMFONYPATH%data\bin\symfony plugin:publish-assets
ECHO.
ECHO Install the assets in your project successful !.
PAUSE
GOTO MENU

:ProVW
ECHO. 
ECHO. Example: http://localhost:%PORTPROJECT%/Location
SET /P CALLMODULENAME=Location:
START /max /wait http://localhost:%PORTPROJECT%/%CALLMODULENAME%
GOTO MENU

:ProALIASADD
SET /P ProALIASADDFOLDER=Folder web:
SET /P ProALIASADDALIASNAME=Alias name:
%XAMPPPATH%apache\bin\pv -f -k apache.exe -q
if not exist %XAMPPPATH%apache\logs\httpd.pid GOTO ProALIASADDStep2
del %XAMPPPATH%apache\logs\httpd.pid
:ProALIASADDStep2
ECHO #======================================================== >> %XAMPPPATH%apache\conf\httpd.conf
ECHO Alias /%ProALIASADDALIASNAME% "%ProALIASADDFOLDER%" >> %XAMPPPATH%apache\conf\httpd.conf
ECHO "<Directory "%ProALIASADDFOLDER%">" >> %XAMPPPATH%apache\conf\httpd.conf
ECHO 	Options Indexes FollowSymLinks MultiViews >> %XAMPPPATH%apache\conf\httpd.conf
ECHO 	AllowOverride all >> %XAMPPPATH%apache\conf\httpd.conf
ECHO 	Order allow,deny >> %XAMPPPATH%apache\conf\httpd.conf
ECHO 	Allow from all >> %XAMPPPATH%apache\conf\httpd.conf
ECHO "</Directory>" >> %XAMPPPATH%apache\conf\httpd.conf
ECHO #======================================================== >> %XAMPPPATH%apache\conf\httpd.conf
START /max /wait NOTEPAD.EXE %XAMPPPATH%apache\conf\httpd.conf
GOTO MENU

:END
ECHO.
ECHO End by user. Any support on www.dehieu.net. Byebye !
PAUSE
